package com.leetcode.string;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * Given a string, find the length of the longest substring without repeating characters.

Examples:

Given "abcabcbb", the answer is "abc", which the length is 3.

Given "bbbbb", the answer is "b", with the length of 1.

Given "pwwkew", the answer is "wke", with the length of 3. Note that the answer must be a substring, "pwke" is a subsequence and not a substring.
 * @author Adiy
 *
 */
public class LongestSubstringWithoutRepeatingCharacters {

	public static void main(String[] args){
		Scanner in=new Scanner(System.in);
		String s=in.nextLine();
		int result=lengthOfLongestSubstring(s);
		System.out.println(result);
	}
	
	public static int lengthOfLongestSubstring(String s) {
	      
		int len=s.length();
		int count=0,i=0;
		int longest=0;
		List<Character> list=new ArrayList<Character>();
		for(i=0;i<len;i++){
			if(!list.contains(s.charAt(i))){
				list.add(s.charAt(i));
				count++;
			}else{
				i--;
				System.out.println(list);
				list.remove(0);
				longest=Math.max(count, longest);
				count--;
			}
		}
		if(i>=len&&longest==0) return s.length();
		return Math.max(count, longest);
    }
}
